<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('PC字段属性配置列表')" />
	<style type="text/css">
		.layui-input{height:30px;}
		/*.layui-btn-container .layui-btn{margin:10px}*/
		/*.layui-table-view .layui-table{margin: 10px 0 0 0;}*/
	</style>
</head>
<body>
<form>
	<div class="layuiadmin-header-box">
		<th:block th:include="listinclude :: searchTop" />
	</div>
</form>
	<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
    <div class="layui-btn-container" style="float: right;margin-right: 20px;">
		<input class="layui-btn layui-table-tools" type="button" lay-submit="" lay-filter="btn_save" value="保存">
		<input class="layui-btn layui-btn-normal layui-table-tools" type="button" lay-submit="" lay-filter="btn_save_close" value="保存并关闭">
		<input class="layui-btn layui-table-tools" type="button" lay-submit="" lay-filter="btn_close" value="关闭">
	</div>
<th:block th:include="include :: footer" />
<script th:src="@{/dhecp/js/selectInTable.js}"></script>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addBtn" shiro:hasPermission="system:dictionaryforfield:add">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增</span></p>
        </div>
        <div class="layui-btn layui-btn-danger layui-table-tools" lay-event="deleteBatch" shiro:hasPermission="system:dictionaryforfield:delete">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">删除</span></p>
        </div>
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addBatch" shiro:hasPermission="system:dictionaryformobilefield:add">
            <p class=" dhicon dh-plus-circle" style="color:white;font-size:14px"><span class="fa_span">批量添加</span></p>
        </div>
        <div class="layui-btn  layui-table-tools" lay-event="copyToMobile" shiro:hasPermission="system:dictionaryformobilefield:add">
            <p class=" dhicon dh-paste" style="color:white;font-size:14px"><span class="fa_span">覆盖手机</span></p>
        </div>
		<div class="layui-btn  layui-table-tools" lay-event="tblm" shiro:hasPermission="system:dictionaryformobilefield:add">
			<p class=" dhicon dh-paste" style="color:white;font-size:14px"><span class="fa_span">同步列名</span></p>
		</div>
    </div>
</script>
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-edit" onclick="$.operate.edit('{{d.guid}}')"  shiro:hasPermission="system:dictionaryforfield:edit">&nbsp;编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" onclick="remove('{{d.guid}}')" shiro:hasPermission="system:dictionaryforfield:delete">&nbsp;删除</a>	         
</script>
<script type="text/html" id="checkbox_fieldFrontConditions">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontConditions' lay-filter='change' value='{{d.fieldFrontConditions}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontConditions==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontConditionsFixed">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontConditionsFixed' lay-filter='change' value='{{d.fieldFrontConditionsFixed}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontConditionsFixed==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontEdit">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontEdit' lay-filter='change' value='{{d.fieldFrontEdit}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontEdit==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontFixed">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontFixed' lay-filter='change' value='{{d.fieldFrontFixed}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontFixed==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontHidden">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontHidden' lay-filter='change' value='{{d.fieldFrontHidden}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontHidden==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontRequired">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontRequired' lay-filter='change' value='{{d.fieldFrontRequired}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontRequired==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontTotal">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontTotal' lay-filter='change' value='{{d.fieldFrontTotal}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontTotal==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontImport">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontImport' lay-filter='change' value='{{d.fieldFrontImport}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontImport==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldKey">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldKey' lay-filter='change' value='{{d.fieldKey}}' lay-skin='switch' lay-text='是|否' {{d.fieldKey==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldNull">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldNull' lay-filter='change' value='{{d.fieldNull}}' lay-skin='switch' lay-text='是|否' {{d.fieldNull==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldExceptEdit">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldExceptEdit' lay-filter='change' value='{{d.fieldExceptEdit}}' lay-skin='switch' lay-text='是|否' {{d.fieldExceptEdit==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontHiddenList">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontHiddenList' lay-filter='change' value='{{d.fieldFrontHiddenList}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontHiddenList==true?'checked':''}}>
</script>
<script type="text/html" id="checkbox_fieldFrontHiddenCallIn">
    <input type='checkbox' tIndex='{{d.LAY_TABLE_INDEX}}' name='fieldFrontHiddenCallIn' lay-filter='change' value='{{d.fieldFrontHiddenCallIn}}' lay-skin='switch' lay-text='是|否' {{d.fieldFrontHiddenCallIn==true?'checked':''}}>
</script>
<script type="text/html" id="dropdown_fieldFrontTop">
    <select data-field="fieldFrontTop" lay-filter="select" lay-search>
		<option value="0" {{d.fieldFrontTop==0?'selected':''}}>制单网格</option>
		<option value="7" {{d.fieldFrontTop==7?'selected':''}}>网格隐藏</option>
		<option value="1" {{d.fieldFrontTop==1?'selected':''}}>表头显示</option>
		<option value="2" {{d.fieldFrontTop==2?'selected':''}}>表头隐藏</option>
		<option value="3" {{d.fieldFrontTop==3?'selected':''}}>制单隐藏</option>
		<option value="5" {{d.fieldFrontTop==5?'selected':''}}>底部显示</option>
		<option value="6" {{d.fieldFrontTop==6?'selected':''}}>底部隐藏</option>
		<option value="8" {{d.fieldFrontTop==8?'selected':''}}>静态网格</option>
	</select>
</script>
<script type="text/html" id="dropdown_fieldFrontType">
    <select data-field="fieldFrontType" lay-filter="select" lay-search>
		<option></option>
		<div th:each="ctt:${controlType}" th:utext="'<option value=\''+${ctt.key}+'\' valuecn=\''+${ctt.value}+'\' {{d.fieldFrontType==\''+${ctt.key}+'\'?\'selected\':\'\'}}>'+${ctt.value}+'</option>'" th:remove="tag"><div>
	</select>
</script>
<script type="text/html" id="dropdown_fieldSearchType">
    <select data-field="fieldSearchType" lay-filter="select" lay-search>
		<option></option>
		<div th:each="fst:${fieldSearchType}" th:utext="'<option value=\''+${fst.key}+'\' valuecn=\''+${fst.value}+'\' {{d.fieldSearchType==\''+${fst.key}+'\'?\'selected\':\'\'}}>'+${fst.value}+'</option>'" th:remove="tag"><div>
	</select>
</script>
<script type="text/html" id="dropdown_fieldFrontTemplet">
    <select data-field="fieldFrontTemplet" lay-filter="select" lay-search>
		<option></option>
		<div th:each="fftt:${fieldFrontTempletType}" th:utext="'<option value=\''+${fftt.key}+'\' valuecn=\''+${fftt.value}+'\' {{d.fieldFrontTemplet==\''+${fftt.key}+'\'?\'selected\':\'\'}}>'+${fftt.value}+'</option>'" th:remove="tag"><div>
    </select>
</script>
<script type="text/html" id="dropdown_fieldFrontAlign">
    <select data-field="fieldFrontAlign" lay-filter="select" lay-search>
		<option></option>
		<div th:each="ffat:${fieldFrontAlignType}" th:utext="'<option value=\''+${ffat.key}+'\' valuecn=\''+${ffat.value}+'\' {{d.fieldFrontAlign==\''+${ffat.key}+'\'?\'selected\':\'\'}}>'+${ffat.value}+'</option>'" th:remove="tag"><div>
    </select>
</script>
<script type="text/html" id="dropdown_fieldFrontConditionsType">
	<select data-field="fieldFrontConditionsType" lay-filter="select" lay-search>
		<option></option>
		<div th:each="ct:${conditionsType}" th:utext="'<option value=\''+${ct.key}+'\' valuecn=\''+${ct.value}+'\' {{d.fieldFrontConditionsType==\''+${ct.key}+'\'?\'selected\':\'\'}}>'+${ct.value}+'</option>'" th:remove="tag"><div>
	</select>
</script>
<script type="text/html" id="dropdown_fieldDataLimit">
	<select data-field="fieldDataLimit" lay-filter="select" lay-search>
		<option></option>
		<div th:each="dt:${dataLimitType}" th:utext="'<option value=\''+${dt.key}+'\' valuecn=\''+${dt.value}+'\' {{d.fieldDataLimit==\''+${dt.key}+'\'?\'selected\':\'\'}}>'+${dt.value}+'</option>'" th:remove="tag"><div>
	</select>
</script>
<script type="text/html" id="dropdown_fieldStandard">
	<select data-field="fieldStandard" lay-filter="select" lay-search th:with="map=${@baseinfosimple.getBaseInfoSimpleData('xtqjbl')}">
		<option></option>
		<div th:each="dt:${map}" th:utext="'<option value=\''+${dt.vid}+'\' valuecn=\''+${dt.vname}+'\' {{d.fieldStandard==\''+${dt.vid}+'\'?\'selected\':\'\'}}>'+${dt.vname}+'</option>'" th:remove="tag"><div>
	</select>
</script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "system/dictionaryforfield",
		gridColumns = [[${gridColumns}]],
		moduleTable = [[${moduleTable}]];
	/*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,laydate,wherestr={};
layui.use(['table','form','layer','jquery','laydate'], function () {
     $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate=layui.laydate;
     $.tablelist.init({
         elem: '#dhtable'
	     ,modalName: "字段属性"
         ,url: prefix + "/tablelist?moduleTable="+window.location.href.split("=")[1]
         ,page:false
         ,limit:1000
         ,createUrl: prefix + "/add?{id}"
         ,updateUrl: prefix + "/edit?guid={id}"
         ,totalRow: gridColumns.totalRow
   		 ,cols: [gridColumns.gridBody
 		 ]
        ,toolbar: '#toolbar'
  		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
        ,height:'full-120'
     });
   	//监听开关动作
	form.on('switch(change)', function(obj){
		var cName=obj.elem.name,cChecked=obj.elem.checked,cIndex=$(this).attr('tindex');
  	  	table.cache.dhtable[cIndex][cName]=cChecked;
    });
	//监听排序事件 
     table.on('sort(ftable)', function(obj){
     	$.tablelist.sort('dhtable',obj);
     });
	//头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 		var checkStatus = table.checkStatus('dhtable');
 	    switch(obj.event){
	    	case 'addBtn'://打开新增页
	    		$.operate.add(obj.config.url);
	    		break;
	    	case 'deleteBatch'://删除字段
	        	if(checkStatus.data.length == 0){
	        		layer.msg("请先选择勾选表格！");
	        	}else{
	        		$.modal.confirmCom('确定要删除么？',function(result){
	        			var pd = [];
	        			$.each(table.cache.dhtable,function(i,v){
	        				if(v['LAY_CHECKED'])pd.push({'guid':v.guid});
	        			})
	        	    	$.operate.post(prefix + "/delete",{'dictionaryForFieldItems':JSON.stringify(pd)},function(result){
		        			if(result.code==0){
		        		        setTimeout(function(){
		        		            layer.closeAll();
		        		            table.reload('dhtable');
		        		        }, 1000);
		        		    }
		        		});
	        	    });
	        	}
    			break;
	    	case 'addBatch'://批量添加字典到手机
	    		if(checkStatus.data.length == 0){
	        		layer.msg("请先选择勾选表格！");
	        	}else{
	        		$.modal.confirmCom('确定要批量添加到手机字典么？',function(result){
	        			var pd = [];
	        			$.each(table.cache.dhtable,function(i,v){
	        				if(v['LAY_CHECKED'])pd.push(v);
	        			})
	        	    	$.operate.post("/system/dictionaryformobilefield/addpost",{'dictionaryForMobileFieldItems':JSON.stringify(pd)});
	        	    });
	        	}
	    		break;
	    	case 'copyToMobile'://复制字典到手机
	    		$.modal.confirmCom('复制所有字段到手机字典，是否覆盖？',function(result){
	    			$.operate.post(prefix + "/copyToMobile",{'moduleTable':window.location.href.split("=")[1]});
        	    });
				break;
	    	case 'tblm'://同步列名
	    		$.modal.confirmCom('是否同步列名？',function(result){
	    			$.operate.post(prefix + "/tblm",{'moduleTable':window.location.href.split("=")[1]});
        	    });
				break;
 	    	case 'fieldSet':
 	    		filedSet(moduleTable);
          		break;
 	    };
 	});
 	//监听行事件
	table.on('tool(ftable)', function (obj) {
		var data = obj.data, event = obj.event;
  		var selectIndex=$("tr").index(obj.tr)-1;
		switch(event.substring(0,6)){//.split("=")[1]截取不适用的情况下可以考虑使用切割
	      	case 'select':
	      		//监听下拉框
	      		form.on('select(select)', function (obj) {
	      			var value = obj.value;//选中的值
	      			$.each(table.cache.dhtable,function(i,v){
						if(v.LAY_TABLE_INDEX==selectIndex){//缓存表内的下标和当前事件行下标的判断
							v[event.substring(7,event.length)]=value;
						}
					}); 
	      		}); 
	      		break;
		}
	});
 	//搜索按钮
  	$('#btn-search').on('click', function () {
  		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
         table.reload('dhtable', {page: {curr: 1},where:wherestr});
      });
  	//监听下拉框——添加条件
  	form.on('select(fft)', function(obj){
  		addMore(this);
  	});
 	//保存
    form.on('submit(btn_save)', function(data){
    	$.operate.post(prefix + "/editpost", {'dictionaryForFieldItems':JSON.stringify(table.cache.dhtable, null, 2)});
	});
  	//保存并关闭
    form.on('submit(btn_save_close)', function(data){
   	 	$.operate.post(prefix + "/editpost", {'dictionaryForFieldItems':JSON.stringify(table.cache.dhtable, null, 2)},setTimeout(function(){top.layui.admin.closeThisTabs()}, 1000));
 	}); 
	//关闭
    form.on('submit(btn_close)', function(data){
    	top.layui.admin.closeThisTabs();
    });
});
//删除
function remove(guid){
	$.operate.remove("确定要删除么？",prefix + "/delete/",{'dictionaryForFieldItems':JSON.stringify([{'guid':guid}])},function(result){
		if(result.code==0){
	        setTimeout(function(){
	            layer.closeAll();
	            table.reload('dhtable');
	        }, 1000);
	    }
	});
}
 </script>
</body>
</html>